﻿
@{
    Layout = "_Layout";
}

<!DOCTYPE html>

<div class="row">
    <div class="col-lg-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>角色列表 </h5>
                <div class="ibox-tools">
                    <a class="btn btn-sm btn-primary pull-right m-t-n-xs" href="/addrule"><strong>添加新的角色</strong></a>


                </div>
            </div>
            <div class="ibox-content">
                <table class="table table-bordered table-hover">
                    <thead>
                        <tr>
                            <th style="width:100px">编号</th>
                            <th style="width:200px">角色名称</th>
                            <th class="col-lg-6">权限</th>
                            <th>#</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr v-for="(item,index) in list">
                            <td>{{index+1}}</td>
                            <td>{{item.name}}</td>
                            <td><a class="label label-info m-r-sm pull-left" style="margin-top:2px" v-for="name in item.actionNames">{{name}}</a></td>
                            <td><a class="label label-primary cursor-pointer" v-bind:href="'/addrule/index/'+item.id">查看</a><span class="label label-danger cursor-pointer m-l-sm" @@click="del(index)">删除</span></td>
                        </tr>
                    </tbody>
                </table>

            </div>
        </div>
    </div>
</div>
<script>
    var vue = new Vue({
        el: "#bind",
        data: {
            list:[]
        },
        created: function () {
            var _this = this;
            _this.getList();
        },
        methods: {
            getList: function () { 
                var _this = this;
                get("/rule/GetRule", {}, function (res) {
                    _this.list = res;
                })
            },
            del: function (index) {
                var _this = this;
                var id = _this.list[index].id;
                confirm("确定删除吗?", function () {
                    post("/rule/del", { id: id }, function (res) {
                        alertDo("删除成功", function () {
                            _this.list.splice(index, 1);
                        }, "success")
                    });
                })

            }
        },
    })
</script>